package test.algos.multiply;

import java.util.List;

import test.algos.sorting.SortUtil;

public class GaussCoeffs {

	private Long aInt;
	private Long bInt;
	private Long cInt;
	private Long dInt;

	private Long firstCoeff;
	private Long secondCoeff;
	private Long thirdCoeff;

	public GaussCoeffs(List<Long> digitList1, List<Long> digitList2) {

		aInt = MultUtil.combineDigits(SortUtil.safeGetSublist(digitList1, 0,
				digitList1.size() / 2));
		bInt = MultUtil.combineDigits(SortUtil.safeGetSublist(digitList1,
				digitList1.size() / 2, digitList1.size()));

		cInt = MultUtil.combineDigits(SortUtil.safeGetSublist(digitList2, 0,
				digitList2.size() / 2));
		dInt = MultUtil.combineDigits(SortUtil.safeGetSublist(digitList2,
				digitList2.size() / 2, digitList2.size()));

	}

	public void computeCoeffs() {

		computeFirstCoeff();
		computeSecondCoeff();
		computeThirdCoeff();

	}

	private void computeFirstCoeff() {

		firstCoeff = multiplier(aInt, cInt);

	}

	private void computeSecondCoeff() {

		secondCoeff = multiplier(bInt, dInt);

	}

	private void computeThirdCoeff() {

		thirdCoeff = multiplier((aInt + bInt), (cInt + dInt)) - firstCoeff
				- secondCoeff;

	}

	private Long multiplier(Long int1, Long int2) {

		if (MultUtil.maxTenPos(int1, int2) >= 2) {
			GaussMultiply multiply = new GaussMultiply();
			return multiply.multiply(int1, int2);

		} else {
			return int1 * int2;
		}

	}

	public Long getFirstCoeff() {
		return firstCoeff;
	}

	public Long getSecondCoeff() {
		return secondCoeff;
	}

	public Long getThirdCoeff() {
		return thirdCoeff;
	}

}
